package com.qzsoft.zhjd.machine.modules.machinedaily.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.machine.modules.machinedaily.dto.MachineDailyListDto;
import com.qzsoft.zhjd.machine.modules.machinedaily.entity.MachineDailyEntity;
import com.qzsoft.zhjd.machine.modules.machinedaily.service.MachineDailyService;

/**
 * @ClassName MachineDailyController
 * @Description 设备日报控制器
 * @author linhuawei
 * @since 2021-11-05
 */
@RestController
@RequestMapping("/api/machineDaily")
public class MachineDailyController {
    
    @Autowired
    private MachineDailyService machineDailyService;
    
    /**
     * @Title page
     * @Description 获取日报数据分页列表
     * @param params 查询条件
     * @return 日报数据分页列表
     */
    @RequiresPermissions("api:machineDaily:list")
    @GetMapping("/page")
    public Result<IPage<MachineDailyListDto>> page(@RequestParam Map<String, Object> params){
        IPage<MachineDailyListDto> page = machineDailyService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title pageForMachine
     * @Description 获取指定机械日报列表
     * @param params 查询条件
     * @return 日报列表
     */
    @GetMapping("/page/{machineId}")
    public Result<IPage<MachineDailyEntity>> pageForMachine(@PathVariable("machineId") String machineId, @RequestParam Map<String, Object> params) {
        if(null == params) {
            params = new HashMap<String, Object>();
        }
        params.put("machineId", machineId);
        IPage<MachineDailyEntity> page = machineDailyService.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title dailyWithWorkrecords
     * @Description 获取带有工时记录的数据
     * @param params 查询条件
     * @return 日报列表
     */
    @RequiresPermissions("api:machinedaily:dailywithworkrecords")
    @GetMapping("/dailyWithWorkrecords")
    public Result<IPage<MachineDailyEntity>> dailyWithWorkrecords(@RequestParam Map<String, Object> params) {
        IPage<MachineDailyEntity> page = machineDailyService.dailyWithWorkrecords(params);
        return ResultUtils.ok(page);
    }
    
}
